package com.srxz.mobilepharmacy.util.back;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class BackMessage implements Serializable {
    private Integer status;
    private String message;
    private Map<String, Object> rows = new HashMap<>();

    public static BackMessage success(){
        BackMessage backMessage = new BackMessage();
        backMessage.status = 200;
        backMessage.message = "Successful operation";
        return backMessage;
    }

    public static BackMessage error(String msg){
        BackMessage backMessage = new BackMessage();
        backMessage.status = 10080;
        if(StringUtils.isEmpty(msg)){
            backMessage.message = "operation failed";
        }
        backMessage.message = msg;
        return backMessage;
    }

    /**
     * 服务器异常
     * @return
     */
    public static BackMessage sessionTimeOut(){
        BackMessage backMessage = new BackMessage();
        backMessage.status = 9999;
        backMessage.message = "登陆超时";
        return backMessage;
    }

    /**
     * 服务器异常
     * @return
     */
    public static BackMessage serverException(String msg){
        BackMessage backMessage = new BackMessage();
        backMessage.status = 303;
        if(StringUtils.isEmpty(msg)){
            backMessage.message = "服务器错误";
        }
        backMessage.message = msg;

        return backMessage;
    }

    public BackMessage putData(String key, Object data){
        this.rows.put(key, data);
        return this;
    }


}
